﻿@model Orchard.ContentFields.Settings.NumericFieldSettings
@using System.Globalization

@inject Orchard.DisplayManagement.Theming.IThemeManager ThemeManager
@inject Orchard.DisplayManagement.Descriptors.IShapeTableManager ShapeTableManager

@{
    var theme = await ThemeManager.GetThemeAsync();
    var shapeTable = ShapeTableManager.GetShapeTable(theme?.Id);
    var editorShapes = shapeTable.ShapeBindings.Keys.Where(x => x.StartsWith("NumericField_Option__", StringComparison.OrdinalIgnoreCase));
    var step = Math.Pow(10, 0 - Model.Scale);
    var stepAttribute = step.ToString(CultureInfo.InvariantCulture);
    string minimum = (Model.Minimum.HasValue) ? Math.Round(Model.Minimum.Value, Model.Scale).ToString(CultureInfo.InvariantCulture) : "";
    string maximum = (Model.Maximum.HasValue) ? Math.Round(Model.Maximum.Value, Model.Scale).ToString(CultureInfo.InvariantCulture) : "";
}

<fieldset class="form-group">
    <div class="form-check">
        <label class="form-check-label">
            <input asp-for="Required" type="checkbox" class="form-check-input" />
            <span class="hint">@T["Check if the field is required."]</span>
        </label>
    </div>
</fieldset>

<div class="row">
    <fieldset class="form-group col-sm-6">
        <label asp-for="Editor">@T["What type of editor should be used?"]</label>
        <select asp-for="Editor" class="form-control">
            @foreach (var editorShape in editorShapes)
            {
                dynamic shape = Factory.Create(editorShape);
                shape.Editor = Model.Editor;
                @await DisplayAsync(shape)
            }
        </select>
        <span class="hint">@T["The editor to use. eg: Number, Range"]</span>
    </fieldset>
</div>

<fieldset class="form-group">
    <div class="row col-md">
        <label asp-for="Hint">@T["Hint"]</label>
        <textarea asp-for="Hint" rows="2" class="form-control"></textarea>
        <span class="hint">@T["The hint text to display for this field on the editor."]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-md">
        <label for="Placeholder">@T["Watermark (placeholder)"]</label>
        <input asp-for="Placeholder" type="text" class="form-control" />
        <span class="hint">@T["A hint to display when the input is empty. (optional)"]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-sm">
        <label for="Scale">@T["Scale"]</label>
        <input asp-for="Scale" class="form-control" min="0" max="5" step="1" type="number" />
        <span class="hint">@T["The number of digits after the decimal point."]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-sm">
        <label for="Minimum">@T["Minimum"]</label>
        <input asp-for="Minimum" class="form-control" />@*step="@step" type="number"*@
        <span class="hint">@T["The minimum value allowed. (optional)"]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-sm">
        <label for="Maximum">@T["Maximum"]</label>
        <input asp-for="Maximum" class="form-control" />@*step="@step" type="number"*@
        <span class="hint">@T["The maximum value allowed. (optional)"]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-sm">
        <label for="DefaultValue">@T["Default value"]</label>
        <input asp-for="DefaultValue" class="form-control" min="@minimum" max="@maximum" step="@stepAttribute" type="number" />
        <span class="hint">@T["The default value. (optional)"]</span>
    </div>
</fieldset>